<?
if(!defined('ENVIRONMENT')) define('ENVIRONMENT','online');
if(ENVIRONMENT == 'online') 
{
	$arrServer[0]['host'] = "192.168.0.218";
	$arrServer[0]['user'] = "dbabbs";
	$arrServer[0]['password'] = "dbabbs20080214";
	$arrServer[0]['dbname'] = "db_gm";

	$arrServer[1]['host'] = "192.168.4.136";
	$arrServer[1]['user'] = "dbaunion";
	$arrServer[1]['password'] = "5NcJ57f72j6nScC";
	$arrServer[1]['dbname'] = "uniondb";
}
if(ENVIRONMENT == 'test') 
{
	$arrServer[0]['host'] = "192.168.0.8";
	$arrServer[0]['user'] = "dbashanghai";
	$arrServer[0]['password'] = "dbashanghai20070508";
	$arrServer[0]['dbname'] = "db_gm";

	$arrServer[1]['host'] = "192.168.0.8";
	$arrServer[1]['user'] = "dbashanghai";
	$arrServer[1]['password'] = "dbashanghai20070508";
	$arrServer[1]['dbname'] = "uniondb";
}

connectDb($arrServer[0]['host'],$arrServer[0]['user'],$arrServer[0]['password'],$arrServer[0]['dbname']);

function connectDb($host,$user,$password,$dbname) 
{
	global $dbh;
	$dbh_error='';
	if( $dbh =  mysql_connect($host,$user,$password))
	{
		if(!mysql_select_db($dbname))$dbh_error='select database "'.$dbname.'" error';
		$query='set names UTF8';
		if(!mysql_query($query, $dbh)) $dbh_error='select query: '.$query.' error';
	}
	else  
	{
		$dbh_error='connect database "'.$dbname.'" error';
	}
	if($dbh_error!='') {
		error($dbh_error);
		die($dbh_error);
	}	
}
function changeDbh($dbname=null)
{
	global $arrServer;
	switch($dbname)
	{
		case "union":
             connectDb($arrServer[1]['host'],$arrServer[1]['user'],$arrServer[1]['password'],$arrServer[1]['dbname']);		 
			 break;
		default:
			 connectDb($arrServer[0]['host'],$arrServer[0]['user'],$arrServer[0]['password'],$arrServer[0]['dbname']);
		     break;
	}
}
?>